package com.lingnan.wanxiangxinxun.controller.user;


import com.lingnan.wanxiangxinxun.entity.po.UserComment;
import com.lingnan.wanxiangxinxun.entity.vo.client.UserCommentVO_forNews;
import com.lingnan.wanxiangxinxun.entity.vo.common.PageVO;
import com.lingnan.wanxiangxinxun.entity.vo.common.Result;
import com.lingnan.wanxiangxinxun.service.IUserCommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 * 用户评论表 前端控制器
 * </p>
 *
 * @author swl
 * @since 2025-03-13
 */
@RestController("UserUserCommentController")
@RequestMapping("/user/user-comment")
public class UserCommentController {

    @Autowired
    private IUserCommentService iUserCommentService;


    //新增
    @PostMapping("/add")
    public Result addUserComment(@RequestBody UserComment userComment) {
        userComment.setCreateTime(LocalDateTime.now());
        iUserCommentService.save(userComment);
        return Result.success();
    }


    //删除
    @DeleteMapping("/delete/{ids}")
    public Result deleteUserComment(@PathVariable List<Integer> ids) {
        iUserCommentService.removeBatchByIds(ids);
        return Result.success();
    }


    //查找--返回某一条新闻底下的所有评论
    @GetMapping("/getAllByNewsId/{newsId}")
    public Result getUserCommentByNewsId(@PathVariable Integer newsId,
                                         @RequestParam(defaultValue = "1") long current,
                                         @RequestParam(defaultValue = "10") long size) {
        PageVO<UserCommentVO_forNews> allInCondition = iUserCommentService.getAllByNewsId(newsId, current, size);
        return Result.success(allInCondition);
    }

    //查找--返回某一个用户的所有评论
    @GetMapping("/getAllByUserId/{userId}")
    public Result getUserCommentByUserId(@PathVariable Integer userId,
                                         @RequestParam(defaultValue = "1") long current,
                                         @RequestParam(defaultValue = "10") long size) {
        PageVO<UserComment> allInCondition = iUserCommentService.getAllByUserId(userId, current, size);
        return Result.success(allInCondition);
    }


}
